;layui.define(function(e) {
    layui.use(['table','layer','form','laydate'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,laydate = layui.laydate;
        //展示已知数据
        table.render({
            elem: '#idTest'
            , id: 'listReload'//生成 Layui table 的标识 id，必须提供，用于后文刷新操作
            , url: hostUrl + '/order/queryOrderListPassOrReject?orderstatu=3'
            ,cols: [[ //标题栏
                {field: 'brand_name', title: '品牌'}
                ,{field: 'series_name', title: '车系'}
                ,{field: 'car_type_name', title: '车型', minWidth: 120}
                ,{field: 'customer_name', title: '客户姓名'}
                ,{field: 'sex', title: '性别'}
                ,{field: 'phone', title: '手机号'}
                ,{field: 'level', title: '客户级别'}
                ,{field: 'create_time', title: '订单日期',minWidth: 160}
                ,{field: 'create_time', title: '交车日期',templet: function(d){
                        if(d.orderStatu == '已交车'){
                            return d.create_time;
                        }else{
                            return '-';
                        }
                    }}
                ,{field: 'statu', title: '订单状态'}
                ,{field: 'store_sale_acc_name', title: '销售顾问'}
                ,{field: 'brokerName', title: '经纪人'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:188, align:'center', toolbar: '#barDemo'}
            ]]
            ,height: 500
            ,cellMinWidth: 120
            ,page: true //是否显示分页
        });
        //表刷新方法
        var reloadTable = function () {

            table.reload("listReload", { //此处是上文提到的 初始化标识id
                where: {
                    brandOrSeriesOrTypeName: $("#brandOrSeriesOrTypeName").val(),
                    startDate: $("#startDate").val(),
                    endDate: $("#endDate").val()
                }
            });
        };

        // 查询按钮绑定点击事件
        $("#searchBtn").on("click", function () {
            reloadTable();
        })

        //日期控件
        layui.use(['laydate'], function(){
            var laydate = layui.laydate;
            //常规用法
            laydate.render({
                elem: '#startDate'
            });

            laydate.render({
                elem: '#endDate'
            });
        });

        

    //监听工具条
    table.on('tool(listTable)', function(obj){
        var data = obj.data;
        if(obj.event === 'apprPend'){
        	Layer.openDialogWithCallBack("审核通过详情", hostUrl+'/retailorder/retailorderDetail.do?oper=detail&orderId=' + data.order_id,"500px","800px");
            	 
        }   
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.layadmin-takerates .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
         
        //执行一个laydate实例
        laydate.render({
            elem: '#date'
        });

        form.render();
 

     
        
    });

    
    
    //输出模块
    e("list", {})
});